package com.hhkj.admin.order.controller;

import com.hhkj.admin.common.annotation.Idempotent;
import com.hhkj.admin.order.common.valid.AgreeRefund;
import com.hhkj.admin.order.common.valid.RefundPayout;
import com.hhkj.admin.order.domain.OrderRefund;
import com.hhkj.admin.order.model.req.OrderRefundReq;
import com.hhkj.admin.order.model.res.OrderRefundRes;
import com.hhkj.admin.order.service.biz.OrderRefundBizService;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.v2.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.valid.VAdd;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/refund")
@PermissionPrefix("course:orderRefund")
public class OrderRefundController extends BaseController<OrderRefund, OrderRefundReq, OrderRefundRes, OrderRefundBizService> {

    /**
     * 申请退款
     * @param orderRefundReq
     * @return
     */
    @PostMapping("/apply")
    @Idempotent(userTypeCode = Idempotent.UserTypeCode.SYS_USER, timeout = 2)
    public AjaxResult applyRefund(@RequestBody @Validated(value = VAdd.class) OrderRefundReq orderRefundReq) {
        return AjaxResult.success(this.getBizService().applyRefund(orderRefundReq, true));
    }

    /**
     * 同意退款
     * @param orderRefundReq
     * @return
     */
    @PutMapping("/agree")
    @PreAuthorize("@ss.hasPermi(this, 'audit')")
    public AjaxResult agreeRefund(@RequestBody @Validated(value = AgreeRefund.class) OrderRefundReq orderRefundReq) {
        return AjaxResult.success(this.getBizService().agreeRefund(orderRefundReq));
    }

    /**
     * 打款
     * @param orderRefundReq
     * @return
     */
    @PutMapping("/payout")
    @PreAuthorize("@ss.hasPermi(this, 'audit')")
    @Idempotent(userTypeCode = Idempotent.UserTypeCode.SYS_USER, timeout = 2)
    public AjaxResult payout(@RequestBody @Validated(value = RefundPayout.class) OrderRefundReq orderRefundReq) {
        return AjaxResult.success(this.getBizService().payout(orderRefundReq, null));
    }
}
